package cmd

import (
	"fmt"
	cli "github.com/urfave/cli/v2"
)

var (
	startUrl, removeUrl, newUrl, stopUrl string
)

var Commands = []*cli.Command{
	{
		Name:     "start",
		Aliases:  []string{"s"},
		Usage:    "start a task to the list",
		Category: "Service",
		Action: func(c *cli.Context) error {
			fmt.Println("added task: ", c.Args().First())
			return nil
		},
	},
	{
		Name:     "node",
		Aliases:  []string{"n"},
		Usage:    "options for task",
		Category: "Node",

		Subcommands: []*cli.Command{
			{
				Name:  "start",
				Usage: "start an existing node",
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:        "url",
						Aliases:     []string{"u"},
						Usage:       "node url",
						Destination: &startUrl,
					},
				},
				Action: func(c *cli.Context) error {
					fmt.Println("start an node", startUrl)
					return nil
				},
			},
			{
				Name:  "remove",
				Usage: "remove an existing node",
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:        "url",
						Aliases:     []string{"u"},
						Usage:       "node url",
						Destination: &removeUrl,
					},
				},
				Action: func(c *cli.Context) error {
					fmt.Println("removed node: ", removeUrl)
					return nil
				},
			},
			{
				Name:  "new",
				Usage: "new an node",
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:        "url",
						Aliases:     []string{"u"},
						Usage:       "node url",
						Destination: &newUrl,
					},
				},
				Action: func(c *cli.Context) error {
					fmt.Println("new node", newUrl)
					return nil
				},
			},
			{
				Name:  "stop",
				Usage: "stop an node",
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:        "url",
						Aliases:     []string{"u"},
						Usage:       "node url",
						Destination: &stopUrl,
					},
				},
				Action: func(c *cli.Context) error {
					fmt.Println("new node", stopUrl)
					return nil
				},
			},
		},
	},
}
